<?php
/**
 *
 *
 *
 */
class Yz_Form_Renderer_Table
    extends Yz_Form_Renderer_Abstract
    implements Yz_Form_Renderer_Interface
{


    // ### subject to i18n ###
    protected $submitText = "OK";



    protected function renderElementDefault(Yz_Form_Element_Interface $element, Yz_Template_Interface $template)
    {
        $css = $element->exception ? ' class="yz-error"' : "";
        $localizedName = $template->translate($element->name);
        $o = "<tr><td{$css}>{$localizedName}</td><td>";

        $o .= $element->render($template);
        $o .= "</td></tr>\n";
        return $o;
    }

    /**
     *
     *
     */
    protected function renderElementSubmit(Yz_Template_Interface $template)
    {
        $submitText = $template->translate($this->submitText);
        $o = <<<html
<tr><td>&nbsp;</td><td>
    <input type="submit" value="{$submitText}" />
</td></tr>\n
html;
        return $o;
    }



    protected function openFormHTML(Yz_Template_Interface $template)
    {
        $o = parent::openFormHTML($template);
        $o .= <<<html
            <table>\n
html;
        return $o;
    }

    protected function closeFormHTML(Yz_Template_Interface $template)
    {
        $o = parent::closeFormHTML($template);
        $o1 = <<<html
            </table>\n
html;
        $o =  $o1
            . $this->renderElementSubmit($template)
            . $o
            ;
        return $o;
    }


}
